package com.lovo.exception;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.InputMismatchException;
import java.util.Scanner;

public class TestException {


    public void a(){
        System.out.println("进入方法a");
        b();
        System.out.println("退出方法a");
    }
    public void b(){
        System.out.println("进入方法b");
        c();
        System.out.println("退出方法b");
    }
    public void c(){
        System.out.println("进入方法c");
        d();
        System.out.println("退出方法c");
    }
    public void d(){
        System.out.println("进入方法d");
        try{
            int a = 100/0;
            int [] ary = {1,2};
            ary[3] = 3;
            System.out.println("继续");
        }catch(ArithmeticException e){
            System.out.println(e.getMessage());
            e.printStackTrace();
        }catch(Exception e){
            System.out.println("未知异常：" + e.getMessage());
            e.printStackTrace();
        }

        System.out.println("退出方法d");
    }

    public void method(){
        try{
            String s = "null";
            System.out.println("字符串：" + s.toString());
            int a = 100 / 1;
//            return;
            System.exit(0);
        }catch(NullPointerException e){
            e.printStackTrace();
//            return;
        }finally {
            System.out.println("finally被执行");
        }
        System.out.println("GO ON");
    }
    int x = 9;
    public int getX(){

        try{
            return x;
        }catch(Exception e){
            return 2;
        }finally {
            x += 2;
        }
    }

    public static void main(String[] args) {
        TestException testException = new TestException();
//        testException.a();
//        testException.method();
        System.out.println(testException.getX());
        System.out.println(testException.getX());
//        Scanner sc = new Scanner(System.in);
//        while(true){
//            try{
//                System.out.println("请输入数字：");
//                int input = sc.nextInt();
//                System.out.println("输入的数字：" + input);
//                break;
//            }catch(InputMismatchException e){
////                e.printStackTrace();
//                System.out.println("请重新输入");
//                sc.next();
//
//            }
//        }

        try {
            Object fil = new FileInputStream("d:/2.txt");
            String s = (String)fil;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }
}
